import com.mastercard.labs.Bank
import com.mastercard.labs.Card
import com.mastercard.labs.Merchant
import com.mastercard.labs.Transaction
import com.mastercard.labs.User
import com.mastercard.labs.UserCard
import com.mastercard.labs.Category

class BootStrap {
	def ocbc, uob, dbs //banks
	def ocbcCard, uobCard, dbsCard //cards
	def user
	def audi, nike, lv //merchants
	def cal = Calendar.getInstance()
	// Category
	def grocery, fashion, electronics, travel, food, transportation, art
	def entertainment, utility, car, watch, book, jewelry
	

	def init = { servletContext ->
		setupUser()
		setupBank()
		setupCategory()
		setupMerchant()
		setupCard()
		setupTransaction()
	}
	def destroy = {
	}

	
	// Setup user
	def setupUser() {
		println "setupUser ..."
		user = new User()
		user.username = "david"
		user.name = "David Beckham"
		user.email = "david@gmail.com"
		user.phone = "98765432"
		user.save()
	}
	
	// Setup categories
	def setupCategory() {
		println "setupCategory ..."
		def grocery = new Category()
		grocery.name = "Grocery"
		grocery.save()
		
		fashion = new Category()
		fashion.name = "Fashion"
		fashion.save()
		
		electronics = new Category()
		electronics.name = "Electronics"
		electronics.save()

		travel = new Category()
		travel.name = "Travel"
		travel.save()		
		
		food = new Category()
		food.name = "Food"
		food.save()		
		
		transportation = new Category()
		transportation.name = "Transportation"
		transportation.save()		
		
		art = new Category()
		art.name = "Art"
		art.save()

		entertainment = new Category()
		entertainment.name = "Entertainment"
		entertainment.save()
		
		utility = new Category()
		utility.name = "Utility"
		utility.save()		
		
		car = new Category()
		car.name = "Car"
		car.save()
		
		book = new Category()
		book.name = "Book"
		book.save()
		
		jewelry = new Category()
		jewelry.name = "Jewelry"
		jewelry.save()
	}
	
	// Setup merchant
	def setupMerchant() {
		println "setupMerchant ..."
		audi = new Merchant()
		audi.name = "Audi"
		audi.country = "Singapore"
		audi.logo = "http://images.wikia.com/gran-turismo/images/7/7f/Audi_logo.jpg"
		audi.categories = [car]
		audi.save()
		
		nike = new Merchant()
		nike.name = "Nike"
		nike.country = "Singapore"
		nike.logo = "http://www.logoinn.net/wp-content/uploads/2010/03/Nike-Logo.jpg"
		nike.categories = [fashion]
		nike.save()
		
		lv = new Merchant()
		lv.name = "Louis Vuitton"
		lv.country = "Singapore"
		lv.logo = "http://upload.wikimedia.org/wikipedia/commons/thumb/d/d5/Louis_Vuitton_Logo.svg/246px-Louis_Vuitton_Logo.svg.png"
		lv.categories = [fashion]
		lv.save()
	}

	// Setup banks
	def setupBank() {
		println "setupBank ..."
		ocbc = new Bank();
		ocbc.name = "OCBC"
		ocbc.country = "Singapore"
		ocbc.logo = "http://www.ocbc.com/assets/images/main_logo.png"
		ocbc.save()
		
		uob = new Bank()
		uob.name = "UOB"
		uob.country = "Singapore"
		uob.logo = "http://www.uobgroup.com/assets/images/2012/uob-main-logo.png"
		uob.save()
		
		dbs = new Bank()
		dbs.name = "DBS"
		dbs.country = "Singapore"
		dbs.logo = "http://www.dbs.com.sg/Resources/index/img/common/DBSlogo.gif"
		dbs.save()
	}

	// Setup card and link to user
	def setupCard() {
		println "setupCard ..."
		ocbcCard = new Card()
		ocbcCard.brand = "Platinum"
		ocbcCard.bank = ocbc
		ocbcCard.holder = "David Beckham"
		ocbcCard.number = "5111111111111111"
		ocbcCard.expiry = "11/14"
		ocbcCard.cvv2 = "321"
		ocbcCard.save()
		
		uobCard = new Card()
		uobCard.brand = "Gold"
		uobCard.bank = uob
		uobCard.holder = "David Beckham"
		uobCard.number = "5222222222222222"
		uobCard.expiry = "10/13"
		uobCard.cvv2 = "124"
		uobCard.save()
		
		dbsCard = new Card()
		dbsCard.brand = "Titanium"
		dbsCard.bank = dbs
		dbsCard.holder = "David Beckham"
		dbsCard.number = "5333333333333333"
		dbsCard.expiry = "08/13"
		dbsCard.cvv2 = "890"
		dbsCard.save()
		
		// Link to user
		def userCardOcbc = new UserCard()
		userCardOcbc.user = user
		userCardOcbc.card = ocbcCard
		userCardOcbc.save()
		
		def userCarUob = new UserCard()
		userCarUob.user = user
		userCarUob.card = uobCard
		userCarUob.save()
		
		def userCardDbs = new UserCard()
		userCardDbs.user = user
		userCardDbs.card = dbsCard
		userCardDbs.save()
	}

	// Setup transaction and link to user
	def setupTransaction() {
		println "setupTransaction ..."
		
		cal.set(2012, 1, 2)
		def transactionOcbc = new Transaction()
		transactionOcbc.amount = 3050
		transactionOcbc.card = ocbcCard
		transactionOcbc.type = "S"
		transactionOcbc.currency = "SGD"
		transactionOcbc.txnDate = cal.getTime()
		transactionOcbc.merchant = lv
		transactionOcbc.description = "New wallet"
		transactionOcbc.save()
		
		def transactionOcbc1 = new Transaction()
		transactionOcbc1.amount = 3050
		transactionOcbc1.card = ocbcCard
		transactionOcbc1.type = "S"
		transactionOcbc1.currency = "SGD"
		cal.set(2012, 2, 2)
		transactionOcbc1.txnDate = cal.getTime()
		transactionOcbc1.merchant = lv
		transactionOcbc1.description = "New wallet"
		transactionOcbc1.save()

		def transactionOcbc2 = new Transaction()
		transactionOcbc2.amount = 3050
		transactionOcbc2.card = ocbcCard
		transactionOcbc2.type = "S"
		transactionOcbc2.currency = "SGD"
		cal.set(2012, 3, 2)
		transactionOcbc2.txnDate = cal.getTime()
		transactionOcbc2.merchant = lv
		transactionOcbc2.description = "New wallet"
		transactionOcbc2.save()
		
		def transactionOcbc4 = new Transaction()
		transactionOcbc4.amount = 3050
		transactionOcbc4.card = ocbcCard
		transactionOcbc4.type = "S"
		transactionOcbc4.currency = "SGD"
		cal.set(2012, 4, 2)
		transactionOcbc4.txnDate = cal.getTime()
		transactionOcbc4.merchant = lv
		transactionOcbc4.description = "New wallet"
		transactionOcbc4.save()
		
		def transactionOcbc5 = new Transaction()
		transactionOcbc5.amount = 3050
		transactionOcbc5.card = ocbcCard
		transactionOcbc5.type = "S"
		transactionOcbc5.currency = "SGD"
		cal.set(2012, 5, 2)
		transactionOcbc5.txnDate = cal.getTime()
		transactionOcbc5.merchant = lv
		transactionOcbc5.description = "New wallet"
		transactionOcbc5.save()
		
		def transactionOcbc6 = new Transaction()
		transactionOcbc6.amount = 3050
		transactionOcbc6.card = ocbcCard
		transactionOcbc6.type = "S"
		transactionOcbc6.currency = "SGD"
		cal.set(2012, 6, 2)
		transactionOcbc6.txnDate = cal.getTime()
		transactionOcbc6.merchant = lv
		transactionOcbc6.description = "New wallet"
		transactionOcbc6.save()
		
		def transactionOcbc7 = new Transaction()
		transactionOcbc7.amount = 3050
		transactionOcbc7.card = ocbcCard
		transactionOcbc7.type = "S"
		transactionOcbc7.currency = "SGD"
		cal.set(2012, 7, 2)
		transactionOcbc7.txnDate = cal.getTime()
		transactionOcbc7.merchant = lv
		transactionOcbc7.description = "New wallet"
		transactionOcbc7.save()
		
		def transactionOcbc8 = new Transaction()
		transactionOcbc8.amount = 3050
		transactionOcbc8.card = ocbcCard
		transactionOcbc8.type = "S"
		transactionOcbc8.currency = "SGD"
		cal.set(2012, 8, 2)
		transactionOcbc8.txnDate = cal.getTime()
		transactionOcbc8.merchant = lv
		transactionOcbc8.description = "New wallet"
		transactionOcbc8.save()
		
		def transactionOcbc9 = new Transaction()
		transactionOcbc9.amount = 3050
		transactionOcbc9.card = ocbcCard
		transactionOcbc9.type = "S"
		transactionOcbc9.currency = "SGD"
		cal.set(2012, 9, 2)
		transactionOcbc9.txnDate = cal.getTime()
		transactionOcbc9.merchant = lv
		transactionOcbc9.description = "New wallet"
		transactionOcbc9.save()
		
		
		def transactionUob = new Transaction()
		transactionUob.amount = 10000
		transactionUob.card = uobCard
		transactionUob.type = "S"
		transactionUob.currency = "SGD"
		transactionUob.txnDate = new Date()
		transactionUob.merchant = audi
		transactionUob.description = "Service fee"
		transactionUob.save()
		
		def transactionDbs = new Transaction()
		transactionDbs.amount = 7050
		transactionDbs.card = dbsCard
		transactionDbs.type = "S"
		transactionDbs.currency = "SGD"
		transactionDbs.txnDate = new Date()
		transactionDbs.merchant = nike
		transactionDbs.description = "New shoes"
		transactionDbs.save()
	}

}
